/*
 * @Author: cooper
 * @Date: 2025-04-03 21:12:04
 * @Wechat: cmd_develop
 * @Description:
 */
#include "reg_key.h"
u32 ARM_REG[ARM_KEYS_NUM] = {0};             // 每个索引对应一个键的值
u32 LONG_ARM_REG[ARM_LONG_KEYS_NUM] = {0};   // 每个索引对应一个键的值
u32 SHORT_ARM_REG[ARM_SHORT_KEYS_NUM] = {0}; // 每个索引对应一个键的值
u32 Z_ARM_REG[ARM_Z_KEYS_NUM] = {0};         // 每个索引对应一个键的值
u32 PAW_ARM_REG[ARM_PAW_KEYS_NUM] = {0};     // 每个索引对应一个键的值
u32 STICK_ARM_REG[ARM_STICK_KEYS_NUM] = {0}; // 每个索引对应一个键的值

u32 LIFT_REG[LIFT_KEYS_NUM] = {0};               // 每个索引对应一个键的值
u32 UPDOWN_LIFT_REG[LIFT_UPDOWN_KEYS_NUM] = {0}; // 每个索引对应一个键的值
u32 DOOR_LIFT_REG[LIFT_DOOR_KEYS_NUM] = {0};     // 每个索引对应一个键的值

u32 FOOD_REG[FOOD_KEYS_NUM] = {0};
u32 ONE_FOOD_REG[FOOD_ONE_KEYS_NUM] = {0};
u32 TWO_FOOD_REG[FOOD_TWO_KEYS_NUM] = {0};
u32 THREE_FOOD_REG[FOOD_THREE_KEYS_NUM] = {0};
u32 FOUR_FOOD_REG[FOOD_FOUR_KEYS_NUM] = {0};

// 烤位数据
bakepos_config BP_CONFIG[BAKEPOS_TOTAL];

void reg_init(void)
{
    // 长轴相关参数
    LONG_ARM_REG[REG_SPEED] = 300;
    LONG_ARM_REG[REG_ACC] = 200;
    LONG_ARM_REG[REG_ERROR_TIMES] = 0;
    LONG_ARM_REG[REG_POS_0] = 0;
    LONG_ARM_REG[REG_POS_1] = 56000;
    LONG_ARM_REG[REG_POS_2] = 64000;
    LONG_ARM_REG[REG_POS_3] = 75000;
    LONG_ARM_REG[REG_POS_4] = (1) << 16 | (7500);
    LONG_ARM_REG[REG_POS_5] = (1) << 16 | (24500);
    LONG_ARM_REG[REG_POS_6] = (1) << 16 | (33000);
    LONG_ARM_REG[REG_POS_7] = (1) << 16 | (40850);
    LONG_ARM_REG[REG_POS_8] = (1) << 16 | (48500);
    LONG_ARM_REG[REG_POS_9] = (1) << 16 | (57700);
    LONG_ARM_REG[REG_POS_10] = (2) << 16 | (500);
    LONG_ARM_REG[REG_POS_11] = (2) << 16 | (9000);
    LONG_ARM_REG[REG_POS_12] = (2) << 16 | (17500);
    LONG_ARM_REG[REG_POS_13] = (2) << 16 | (26000);
    LONG_ARM_REG[REG_POS_14] = (2) << 16 | (34500);
    LONG_ARM_REG[REG_POS_15] = 0;
    LONG_ARM_REG[REG_POS_16] = 2000;
    LONG_ARM_REG[REG_POS_17] = 36000;
    LONG_ARM_REG[REG_POS_18] = 36000;

    SHORT_ARM_REG[REG_SPEED] = 300;
    SHORT_ARM_REG[REG_ACC] = 200;
    SHORT_ARM_REG[REG_ERROR_TIMES] = 0;
    SHORT_ARM_REG[REG_POS_0] = 0;
    SHORT_ARM_REG[REG_POS_1] = 12500;
    SHORT_ARM_REG[REG_POS_2] = 45500;
    SHORT_ARM_REG[REG_POS_3] = 0;
    SHORT_ARM_REG[REG_POS_4] = 33000;
    SHORT_ARM_REG[REG_POS_5] = 33000;
    SHORT_ARM_REG[REG_POS_6] = (1) << 16;
    SHORT_ARM_REG[REG_POS_7] = 33000;
    SHORT_ARM_REG[REG_POS_8] = (1) << 16 | (7000);
    SHORT_ARM_REG[REG_POS_9] = 6000;

    Z_ARM_REG[REG_SPEED] = 300;
    Z_ARM_REG[REG_ACC] = 100;
    Z_ARM_REG[REG_ERROR_TIMES] = 0;
    Z_ARM_REG[REG_POS_0] = 0;
    Z_ARM_REG[REG_POS_1] = 14000;
    Z_ARM_REG[REG_POS_2] = 7200;
    Z_ARM_REG[REG_POS_3] = 30000;
    Z_ARM_REG[REG_POS_4] = 32500;
    Z_ARM_REG[REG_POS_5] = 12000;
    Z_ARM_REG[REG_POS_6] = 13000;
    Z_ARM_REG[REG_POS_7] = 32000;

    PAW_ARM_REG[REG_SPEED] = 50;
    PAW_ARM_REG[REG_ACC] = 50;
    PAW_ARM_REG[REG_ERROR_TIMES] = 0;
    PAW_ARM_REG[REG_POS_0] = 0;
    PAW_ARM_REG[REG_POS_1] = 4700;

    STICK_ARM_REG[REG_SPEED] = 300;
    STICK_ARM_REG[REG_ACC] = 200;
    STICK_ARM_REG[REG_ERROR_TIMES] = 0;
    STICK_ARM_REG[REG_POS_0] = 0;
    STICK_ARM_REG[REG_POS_1] = (3) << 16 | (43000);

    UPDOWN_LIFT_REG[REG_SPEED] = 1500;
    UPDOWN_LIFT_REG[REG_ACC] = 02;
    UPDOWN_LIFT_REG[REG_ERROR_TIMES] = 0;
    UPDOWN_LIFT_REG[REG_POS_0] = 0;
    UPDOWN_LIFT_REG[REG_POS_1] = 0;                                                  // 下抽屉
    UPDOWN_LIFT_REG[REG_POS_2] = ((unsigned int)(0xFFE7) << 16) | (0xA340 & 0xFFFF); // 上抽屉
    UPDOWN_LIFT_REG[REG_POS_3] = ((unsigned int)(0xFFCA) << 16) | (0x9820 & 0xFFFF); // 等待点
    UPDOWN_LIFT_REG[REG_POS_4] = ((unsigned int)(0xFFB6) << 16) | (0xC200 & 0xFFFF); // 补货点

    DOOR_LIFT_REG[REG_SPEED] = 300;
    DOOR_LIFT_REG[REG_ACC] = 02;
    DOOR_LIFT_REG[REG_ERROR_TIMES] = 0;
    DOOR_LIFT_REG[REG_POS_0] = 0;
    DOOR_LIFT_REG[REG_POS_1] = (0x6C20) << 16 | 0xFFFB; // 门打开

    ONE_FOOD_REG[REG_SPEED] = 300;
    ONE_FOOD_REG[REG_ACC] = 02;
    ONE_FOOD_REG[REG_ERROR_TIMES] = 0;
    ONE_FOOD_REG[REG_POS_0] = 550;

    TWO_FOOD_REG[REG_SPEED] = 300;
    TWO_FOOD_REG[REG_ACC] = 02;
    TWO_FOOD_REG[REG_ERROR_TIMES] = 0;
    TWO_FOOD_REG[REG_POS_0] = 550;

    THREE_FOOD_REG[REG_SPEED] = 300;
    THREE_FOOD_REG[REG_ACC] = 02;
    THREE_FOOD_REG[REG_ERROR_TIMES] = 0;
    THREE_FOOD_REG[REG_POS_0] = 550;

    FOUR_FOOD_REG[REG_SPEED] = 300;
    FOUR_FOOD_REG[REG_ACC] = 02;
    FOUR_FOOD_REG[REG_ERROR_TIMES] = 0;
    FOUR_FOOD_REG[REG_POS_0] = 550;

    // 温控
    // 定位 第一排14个烤位，15个烤管。烤位：28-27-26----15
    // 定位 第二排14个烤位，15个烤管。烤位：14-13-12----1
    for (u8 i = 1; i <= 28; i++)
    {
        if (i <= 14)
        {
            BP_CONFIG[i - 1].long_pos = 1;
            BP_CONFIG[i - 1].short_pos = 2;
        }
        else
        {
            BP_CONFIG[i - 1].long_pos = i - 14;
            BP_CONFIG[i - 1].short_pos = 1;
        }
        BP_CONFIG[i - 1].state = 0;            // 当前状态:0没有 1烤制中 2保温中
        BP_CONFIG[i - 1].cur_temputure = 0;    // 当前温度
        BP_CONFIG[i - 1].bake_temputure = 100; // 烤制时间
        BP_CONFIG[i - 1].taste = 0;            // 烤肠品种
        BP_CONFIG[i - 1].bake_time = 0;        // 烤制时间,单位为秒
        BP_CONFIG[i - 1].keep_temputure = 0;   // 保温温度
        // BP_CONFIG[i - 1].left_pos = (i - 1 + 2) <= 14 ? (i - 1 + 2) : 0; // 最左边没有了
        // BP_CONFIG[i - 1].right_pos = i - 1;
        // BP_CONFIG[i - 1].left_pipe = i + 1;
        // BP_CONFIG[i - 1].right_pipe = i;
    }
}
